﻿'use strict';

const { Sequelize, DataTypes, Op } = require('sequelize');
const fs = require('fs');

//链接数据库
const sequelize = new Sequelize('demo1', 'postgres', 'Wx3339128080', {
    host: 'www.zgxhh.top',
    dialect: 'postgres'
});
//路径
let files = fs.readdirSync(__dirname);
//筛选文件
let resfiles = files.filter(item => {
    return item.endsWith('.js') && item !== 'index.js';
})

let obj = {}; 

// 遍历模型数据
resfiles.forEach(item => {
    let modelName = item.replace('.js', '');//Blog
    let tableName = modelName.toLowerCase();//blog
    console.log(modelName);
    let model = require(__dirname + '/' + item);
    obj[modelName] = sequelize.define(tableName, model);
})
// 实例化sequelize
obj.sequelize = sequelize;
obj.Op = Op;

obj.sync = async () => {
    await sequelize.sync({ force: true });
    obj.Blog.bulkCreate([

        {
            biaoti: '随高',
            zhaiyao: '随高',
            neirong: '随高',
            fenlei: '随高',
            zuozhe: '随高',
            fabiaoshijian: '随高',
        },
        {
            biaoti: '野球拳',
            zhaiyao: '野球拳',
            neirong: '野球拳',
            fenlei: '野球拳',
            zuozhe: '野球拳',
            fabiaoshijian: '野球拳',
        },

    ])


}

 obj.sync();



module.exports = obj

